<template>
  <div class="tank-monitor-wrapper">
    <div class="tank-cards-container">
      <!-- 罐体1 -->
      <div class="tank-card" :class="tank1.status">
        <div class="tank-header">
          <i class="fas fa-database tank-icon"></i>
          <h3>罐体 #1</h3>
          <span class="tank-status-tag" :class="tank1.status">{{ getStatusText(tank1.status) }}</span>
        </div>

        <div class="tank-details">
          <!-- 压力值 -->
          <div class="pressure-item">
            <span class="label">罐内气压:</span>
            <span class="value pressure">{{ tank1.pressure }} MPa</span>
          </div>

          <!-- 开关状态 -->
          <div class="switch-grid">
            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank1.loosenInPlace }">
                <i class="fas fa-toggle-on" v-if="tank1.loosenInPlace"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">旋松</div>
            </div>

            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank1.doorOpen }">
                <i class="fas fa-toggle-on" v-if="tank1.doorOpen"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">罐门开</div>
            </div>

            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank1.vacuumValve }">
                <i class="fas fa-toggle-on" v-if="tank1.vacuumValve"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">破空阀</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 罐体2 -->
      <div class="tank-card" :class="tank2.status">
        <div class="tank-header">
          <i class="fas fa-database tank-icon"></i>
          <h3>罐体 #2</h3>
          <span class="tank-status-tag" :class="tank2.status">{{ getStatusText(tank2.status) }}</span>
        </div>

        <div class="tank-details">
          <!-- 压力值 -->
          <div class="pressure-item">
            <span class="label">罐内气压:</span>
            <span class="value pressure">{{ tank2.pressure }} MPa</span>
          </div>

          <!-- 开关状态 -->
          <div class="switch-grid">
            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank2.loosenInPlace }">
                <i class="fas fa-toggle-on" v-if="tank2.loosenInPlace"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">旋松</div>
            </div>

            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank2.doorClosed }">
                <i class="fas fa-toggle-on" v-if="tank2.doorClosed"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">罐门关</div>
            </div>

            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank2.vacuumValve }">
                <i class="fas fa-toggle-on" v-if="tank2.vacuumValve"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">破空阀</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 罐体3 -->
      <div class="tank-card" :class="tank3.status">
        <div class="tank-header">
          <i class="fas fa-database tank-icon"></i>
          <h3>罐体 #3</h3>
          <span class="tank-status-tag" :class="tank3.status">{{ getStatusText(tank3.status) }}</span>
        </div>

        <div class="tank-details">
          <!-- 压力值 -->
          <div class="pressure-item">
            <span class="label">罐内气压:</span>
            <span class="value pressure">{{ tank3.pressure }} MPa</span>
          </div>

          <!-- 开关状态 -->
          <div class="switch-grid">
            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank3.loosenInPlace }">
                <i class="fas fa-toggle-on" v-if="tank3.loosenInPlace"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">旋松</div>
            </div>

            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank3.doorOpen }">
                <i class="fas fa-toggle-on" v-if="tank3.doorOpen"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">罐门开</div>
            </div>

            <div class="switch-item">
              <div class="switch-icon" :class="{ 'on': tank3.vacuumValve }">
                <i class="fas fa-toggle-on" v-if="tank3.vacuumValve"></i>
                <i class="fas fa-toggle-off" v-else></i>
              </div>
              <div class="switch-label">破空阀</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive } from "vue";

export default defineComponent({
  setup() {
    // 罐体1: 舱位试件装填中
    const tank1 = reactive({
      status: "loading",
      pressure: "0.8",
      loosenInPlace: true,
      tightenInPlace: false,
      doorOpen: true,
      doorClosed: false,
      motorFault: false,
      vacuumValve: true
    });

    // 罐体2: 罐体耐压中
    const tank2 = reactive({
      status: "pressurizing",
      pressure: "15.2",
      loosenInPlace: false,
      tightenInPlace: true,
      doorOpen: false,
      doorClosed: true,
      motorFault: false,
      vacuumValve: false
    });

    // 罐体3: 气体处理中
    const tank3 = reactive({
      status: "processing",
      pressure: "2.1",
      loosenInPlace: false,
      tightenInPlace: false,
      doorOpen: false,
      doorClosed: true,
      motorFault: true,
      vacuumValve: true
    });

    // 获取状态文本
    const getStatusText = (status) => {
      const statusMap = {
        loading: "装填中",
        pressurizing: "耐压中",
        processing: "处理中"
      };
      return statusMap[status] || status;
    };

    return {
      tank1,
      tank2,
      tank3,
      getStatusText
    };
  },
});
</script>

<style lang="scss" scoped>
.tank-monitor-wrapper {
  padding: 15px;
  height: 100%;
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  backdrop-filter: blur(5px);
}

.tank-cards-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.tank-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    border-color: rgba(79, 195, 247, 0.5);
  }

  &.loading {
    border-left: 4px solid #4fc3f7;
  }

  &.pressurizing {
    border-left: 4px solid #66bb6a;
  }

  &.processing {
    border-left: 4px solid #ff9800;
  }
}

.tank-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;

  .tank-icon {
    font-size: 1.4rem;
    color: #4fc3f7;
  }

  h3 {
    color: #fff;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    flex: 1;
  }

  .tank-status-tag {
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;

    &.loading {
      background: rgba(79, 195, 247, 0.2);
      color: #4fc3f7;
    }

    &.pressurizing {
      background: rgba(102, 187, 106, 0.2);
      color: #66bb6a;
    }

    &.processing {
      background: rgba(255, 152, 0, 0.2);
      color: #ff9800;
    }
  }
}

.tank-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pressure-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);

  .label {
    color: #aaa;
    font-size: 0.85rem;
  }

  .value.pressure {
    color: #4fc3f7;
    font-size: 0.9rem;
    font-weight: 600;
  }
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: 1;
}

.switch-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;

  .switch-icon {
    font-size: 1.2rem;
    color: #777;

    &.on {
      color: #66bb6a;
    }

    &.error {
      color: #f44336;
    }
  }

  .switch-label {
    color: #ccc;
    font-size: 0.8rem;
    white-space: nowrap;
  }
}

// 响应式设计
@media (max-width: 768px) {
  .tank-monitor-wrapper {
    padding: 12px;
  }

  .tank-cards-container {
    gap: 8px;
  }

  .tank-card {
    padding: 10px;
  }

  .tank-header {
    gap: 6px;
    margin-bottom: 5px;

    .tank-icon {
      font-size: 1.2rem;
    }

    h3 {
      font-size: 0.9rem;
    }

    .tank-status-tag {
      font-size: 0.7rem;
      padding: 2px 6px;
    }
  }

  .pressure-item {
    padding: 4px 0;

    .label,
    .value {
      font-size: 0.8rem;
    }
  }

  .switch-grid {
    gap: 6px;
  }

  .switch-item {
    padding: 6px 4px;
    gap: 5px;

    .switch-icon {
      font-size: 1rem;
    }

    .switch-label {
      font-size: 0.75rem;
    }
  }
}

@media (max-width: 480px) {
  .switch-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tank-header {
    .tank-icon {
      font-size: 1rem;
    }
  }
}
</style>